package com.yihaodian.index.meta.shard;

/**
 * Shard routing represents the state of a shard instance allocated in the
 * cluster.
 * 
 */
public class ShardRouting {
	public enum Status {
		INIT, START
	}

	private ShardId shardId;

	private Status status;

	private boolean enable;

	private String version;

	protected ShardRouting() {

	}

	public ShardRouting(ShardRouting sr) {
		this.shardId = sr.shardId;
		this.enable = sr.enable;
		this.status = sr.status;
		this.version = sr.version;
	}

	public ShardRouting(ShardId shardId) {
		this.shardId = shardId;
		this.enable = true;
		this.status = Status.START;
	}

	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	public boolean isEnable() {
		return enable;
	}

	public void setEnable(boolean enable) {
		this.enable = enable;
	}

	public ShardId getShardId() {
		return shardId;
	}

	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((shardId == null) ? 0 : shardId.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ShardRouting other = (ShardRouting) obj;
		if (shardId == null) {
			if (other.shardId != null)
				return false;
		} else if (!shardId.equals(other.shardId))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "ShardRouting [shardId=" + shardId + ", status=" + status
				+ ", enable=" + enable + ", version=" + version + "]";
	}

}
